*-------------------------------------------------------------------------------------------------------------*
* The Causal Effects of R&D Grants: Evidence from a Regression Discontinuity (Santoleri et al., 2020)
*-------------------------------------------------------------------------------------------------------------*

/// Table 2: Balancing tests of baseline observables and pre-award outcomes

use $data_path/DATA_ALL_FINAL.dta, clear 

* list of pre-determined variables
global balance ln_citw_patents_pre_w pe_pre revenues_pre_w assets_pre_w employees_pre_w  ln_age  cashflow_asset_pre_w profitmargin_tm1  high_tech  /*south*/ log_gdp_pc vc_hub  

* controls for polinomyal orders on both sides of the threshold
global linear    c.rank#i.award
global quadratic c.rank#i.award c.rank#c.rank#i.award

gen log_gdp_pc = ln(gdp_pc)

* regression loops reproducing Table 2
cap erase $output/Table_2.txt
cap erase $output/Table_2.tex
eststo clear
foreach var of varlist $balance {
    est clear
	eststo: reghdfe `var' award $linear if phase_smei==2 , a(competition) cluster(competition)
	eststo: reghdfe `var' award $linear if phase_smei==2 & inrange(rank, -10,10) , a(competition) cluster(competition)
	eststo: reghdfe `var' award $linear if phase_smei==2 & inrange(rank, -5,5) , a(competition) cluster(competition)
	eststo: reghdfe `var' award $quadratic if phase_smei==2 , a(competition) cluster(competition)
	eststo: reghdfe `var' award $quadratic if phase_smei==2 & inrange(rank, -10,10) , a(competition) cluster(competition)
	eststo: reghdfe `var' award $quadratic if phase_smei==2 & inrange(rank, -5,5) , a(competition) cluster(competition)
	esttab est* using $output/Table_2.txt, append star(** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat( ) title(`e(depvar)') mtitles(All 10 5 All 10 5 ) ///
	coeflabels(award "Grant") varwidth(25) nonote
	esttab est* using $output/Table_2.tex, append star(** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat( ) title(`e(depvar)') mtitles(All 10 5 All 10 5 ) ///
	coeflabels(award "Grant") varwidth(25) nonote
}

